import argparse
from cyber_search_engine.shodan import Shodan
from cyber_search_engine.zoomeye import ZoomeyeScan, Zoomeye
from httpx.httpx import HTTPX
from config.settings import HTTPX_EXEC_PATH
from config.settings import AWVS_TEST_API
from rapiddns.rapiddns import RapidDNS, RapidDnsScan
from awvs.awvs import AWVS
from goby.goby import Goby

def workflow_domain_ip(domains: list, save_path=None):
    awvs = AWVS()
    for domain in domains:
        
        save_path = f'res/{domain}.xlsx'
        print(f'存储位置 {save_path}')
        rapid = RapidDnsScan(domain)
        rapid.run(save_path)
        subdomains = list(rapid.subdomains)
        ips = rapid.A
        logger.info('存活性检测')
        httpx = HTTPX(HTTPX_EXEC_PATH, subdomains)
        httpx.run(save_path)
        logger.info('awvs检测')
        awvs.run(httpx.results, save_path=save_path)
        print('zoomeye检测')
        zoom = Zoomeye(ips)
        zoom.run(save_path)
        print('shodan检测')
        shodan = Shodan(ips)
        shodan.run(save_path)
        print('goby检测')
        goby = Goby()
        goby.run(ips, save_path=save_path)
        print('运行结束')





if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Domain or File')
    parser.add_argument('--domain', type=str, help='domain')
    parser.add_argument('--file', type=str, help='file path')
    args = parser.parse_args()

    if args.file:
        with open(args.file, 'r') as f:
            my_list = f.read().splitlines()
        workflow_domain_ip(my_list)
        exit(0)
    if args.domain:
        workflow_domain_ip([args.domain])
